@extends('admin.layouts')
@section('css')
    <link rel="stylesheet" href="{{asset('assets/webupload/style.css')}}" />
    <link href="{{asset('assets/css/bootstrap.min.css')}}" rel="stylesheet" />
    <link rel="stylesheet" href="{{asset('assets/css/font-awesome.min.css')}}" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

    <!-- ace styles -->

    <link rel="stylesheet" href="{{asset('assets/css/ace.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-rtl.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/css/ace-skins.min.css')}}" />
    <link rel="stylesheet" href="{{asset('assets/webupload/webuploader.css')}}" />
    <script src="{{asset('assets/js/ace-extra.min.js')}}"></script>
    {{--时间样式--}}
    <link rel="stylesheet" href="{{asset('assets/css/datepicker.css')}}" />
    <style>
        .cover{
            border: 1px solid #AAA;
            padding: 2px;
            background-color: #FFF;
        }
    </style>
@endsection
@section('content')
    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="{{url('admin/index')}}">首页</a>
                </li>

                <li>
                    <a >图片管理</a>
                </li>
                <li class="active">所有图片</li>
            </ul><!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
                </form>
            </div><!-- #nav-search -->
        </div>

        <div class="page-content">
            <div class="page-header">
                <h1>
                    图片管理
                    <small>
                        <i class="icon-double-angle-right"></i>
                        所有图片
                    </small>
                </h1>
            </div><!-- /.page-header -->

            <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <div class="row">
                        <form action="{{url('admin/imglist/1')}}" method="post">
                            <div class="col-md-3 col-xs-12">
                                <div class="input-group">
                                    <input class="form-control date-picker" value="{{$startTime}}" name="start_time" placeholder="开始创建时间" id="id-date-picker-1" type="text" data-date-format="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                        <i class="icon-calendar bigger-110"></i>
                                    </span>
                                </div>
                            </div>
                            {{csrf_field()}}
                            <div class="col-md-3 col-xs-12">
                                <div class="input-group">
                                    <input class="form-control date-picker" value="{{$endTime}}" name="end_time" placeholder="结束创建时间" id="id-date-picker-2" type="text" data-date-format="yyyy-mm-dd" />
                                    <span class="input-group-addon">
                                        <i class="icon-calendar bigger-110"></i>
                                    </span>
                                </div>
                            </div>
                            <div class="col-md-3 col-xs-12">
                                <div class="input-group">
                                    <select name="category_id" id="category_id" class="form-control">
                                        <option value="">==选择图片分类==</option>
                                        @foreach($category as $v)
                                            <option value="{{$v['id']}}"
                                                    @if($category_id==$v['id'])
                                                    selected=""
                                                    @endif
                                            >{{$v['category']}}</option>
                                        @endforeach
                                    </select>
                                <span class="input-group-addon">
                                    <i class="icon-bookmark-empty bigger-110"></i>
                                </span>
                                </div>
                            </div>

                            <div class="col-md-3 col-xs-12">
                                <div class="input-group">
                                    <input type="text" name="title" id="searchTitle" class="form-control search-query" value="{{$titler}}" placeholder="输入文章标题搜索..." />
                                <span class="input-group-btn">
                                    <button type="submit" class="btn btn-purple btn-sm">
                                        搜索
                                        <i class="icon-search icon-on-right bigger-110"></i>
                                    </button>
                                </span>
                                </div>
                            </div>
                        </form>
                    </div>
                    <hr>
                    <div id="timeline-1">
                        <div class="row">
                            <div class="col-xs-12 col-sm-10 col-sm-offset-1">
                                <div class="timeline-container">
                                   {{-- <div class="timeline-label">
													<span class="label label-success arrowed-in-right label-lg">
														<b>Yesterday</b>
													</span>
                                    </div>--}}
                                    @if(sizeof($imglist)>0)
                                @foreach($imglist as $v)
                                    <div class="timeline-items" id="id{{$v['id']}}">
                                        <div class="timeline-item clearfix">
                                            <div class="timeline-info">
                                                {{--<i class="timeline-indicator icon-picture btn btn-info"></i>--}}
                                                <img alt="Susan" src="{{json_decode($v['images'])[0]}}-40X40" />
                                                <span class="label label-info label-sm">{{$v['category']}}</span>
                                            </div>

                                            <div class="widget-box transparent">
                                                <div class="widget-header widget-header-small">
                                                    <h5 class="smaller">{{$v['title']}}</h5>&nbsp;&nbsp;&nbsp;&nbsp;
                                                    @if(empty(Session::get('admin')['is_author']))
                                                    <i class="icon-user"></i>
                                                        @if(!empty($v['username']))
                                                            {{$v['username']}}
                                                        @else
                                                            管理员
                                                        @endif
                                                    @endif
																<span class="widget-toolbar">
                                                                    <a href="#" data-action="collapse">
                                                                        <i class="icon-chevron-up"></i>
                                                                    </a>
																	<i class="icon-time bigger-110"></i>
																	{{date('Y-m-d H:i:s',$v['created_at'])}}
																</span>
                                                </div>

                                                <div class="widget-body">
                                                    <div class="widget-main">
                                                        <div class="clearfix">
                                                            <div class="pull-left col-md-7">
                                                                {{--{!! preg_replace('/<script[\s\S]*?<\/script>/i','',$v['describe'])!!}--}}
                                                                {{mb_substr($v['describe'],0,250,'utf-8')}}...
                                                            </div>

                                                            <div class="pull-right col-md-5" style="float: right">
                                                         {{--       <i class="icon-chevron-left blue bigger-110"></i>

                                                                &nbsp;--}}
                                                                @foreach(json_decode($v['images']) as $k=> $i)
                                                                    @if($k<4)
                                                                        @if($i!='undefined')
                                                                <img alt="Image 4" height="36" src="{{$i}}-40X40" class="pull-right" style="margin-left: 5px" data-rel="tooltip" data-placement="top" title="
                                                <img class='view' src='{{$i}}-185X141' alt='images'  height='135px'>
                                                "/>
                                                                            @endif
                                                                    @endif
                                                                @endforeach
                                                      {{--          &nbsp;
                                                                <i class="icon-chevron-right blue bigger-110"></i>--}}
                                                            </div>
                                                        </div>
                                                        <div class="space-6"></div>
                                                        <div class="widget-toolbox clearfix">
                                                            <div class="pull-left">
                                                                <i class="icon-hand-right grey bigger-125"></i>
                                                                <a href="{{url('admin/editimg/'.$v['id'])}}" class="bigger-110">查看更多 &hellip;</a>
                                                            </div>

                                                            <div class="pull-right action-buttons">
                                                                <a href="{{url('admin/editimg/'.$v['id'])}}" data-rel="tooltipi" data-placement="top" title="修改">
                                                                    <i class="icon-pencil blue bigger-125"></i>
                                                                </a>
                                                                <a href="javascript:;" onclick="updateStatus({{$v['id']}},1)" data-rel="tooltipi" data-placement="top" title="加入回收站">
                                                                    <i class="icon-trash red bigger-130"></i>
                                                                </a>

                                                                <a href="javascript:;" data-rel="tooltipi" data-placement="top" onclick="comments({{$v['id']}})" title="查看评论">
                                                                    <i class="icon-comments green bigger-125"></i>
                                                                </a>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <br>
                                        </div><!-- /.timeline-items -->
                                </div><!-- /.timeline-container -->
                                    @endforeach
                                        @endif
                            </div>
                        </div>
                    </div>
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->

                    {{$imglist->links()}}
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->
        <!-- 模态框（Modal） -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="z-index: 198910159;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">评论</h4>
                    </div>
                    <div class="modal-body">
                        <textarea name="" id="commdsadf" style="width: 100%" rows="10"></textarea>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" id="sadgsdfaew" name="id" value="">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onclick="dsfdgf()">提交更改</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    @endsection

@section('javascript')
    <script src='{{asset('assets/js/jquery-2.0.3.min.js')}}'></script>
    <script src="{{asset('assets/js/bootstrap.min.js')}}"></script>
    <script src="{{asset('assets/js/typeahead-bs2.min.js')}}"></script>

    <!-- ace scripts -->
    <script type="text/javascript" src="{{asset('assets/layer/layer.js')}}"></script>
    <script src="{{asset('assets/js/ace-elements.min.js')}}"></script>
            {{--时间插件--}}
    <script src="{{asset('assets/js/date-time/bootstrap-datepicker.min.js')}}"></script>
    <script src="{{asset('assets/js/ace.min.js')}}"></script>
    <script>
        function getYmdTime(time){
            if(time > 0){
                var dateStr = new Date(time);
                return dateStr.getFullYear() + '-' + (dateStr.getMonth()+1) +'-' + dateStr.getDate() + ' ' + dateStr.getHours() + ':' + dateStr.getMinutes() + ':' + dateStr.getSeconds();
            }else{
                return '末知时间';
            }
        }
        function xiugai(id){
            $("#sadgsdfaew").val(id);
            $("#commdsadf").val($("#comssss"+id).text());
            $("#myModal").modal('show');
        }
        function dsfdgf(){
            var id=$("#sadgsdfaew").val();
            var comment=$("#commdsadf").val();
            $.post('{{url('admin/updatecomment')}}',{"_token":'{{csrf_token()}}','id':id,'comment':comment},function(res){
                layer.msg(res.msg);
                if(res.status){
                    $("#comssss"+id).text(comment);
                    $("#myModal").modal('hide');
                }
            });
        }
        function shanchu(id){
            layer.confirm('你确定要删除？',{
                btn:['确定','取消']
            },function(i){
                layer.close(i);
                layer.load(1);
                $.post('{{url('admin/deletecomment')}}',{"_token":'{{csrf_token()}}','id':id},function(res){
                    layer.closeAll('loading');
                    if(res.status){
                        $("#kojlodgfh"+id).remove();
                        layer.msg(res.msg);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        }
        function comments(id){
            $.post('{{url('admin/getcomment')}}',{'_token':'{{csrf_token()}}','id':id}, function (res) {
                var html='';
                $.each(res,function(i,item){
                    html+="<div class='comments' id='kojlodgfh"+item.id+"'><div class='itemdiv commentdiv'><div class='user'>" +
                            "<img alt='"+item.username+"' src='"+item.avatar+"' /></div><div class='body'>" +
                            "<div class='name'><a href='#'>"+item.username+"</a></div><div class='time'><i class='icon-time'></i>" +
                            "<span class='orange'>"+getYmdTime(item.created_at*1000)+"</span></div><div class='text'><i class='icon-quote-left'></i><span id='comssss"+item.id+"'>" +
                            item.comment+"</span> &hellip;" +
                            "</div></div><div class='tools'><div class='action-buttons bigger-125'><a href='javascript:;' onclick='xiugai("+item.id+")'><i class='icon-pencil blue'>" +
                            "</i></a><a href='javascript:;' onclick='shanchu("+item.id+")'><i class='icon-trash red'></i></a></div></div></div></div>";
                });
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['1000px', '600px'], //宽高
                    title: '评论',
                    content:html
                });
            });
        }
        $('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
            $(this).prev().focus();
        });
        $('[data-rel=tooltipi]').tooltip({html:true});
        $('[data-rel=tooltip]').tooltip({html:true});
        @if(sizeof($imglist)==0)
            layer.msg('没有找到任何东西啊',{icon:5});
            @endif
    </script>

    <script>
        function updateStatus(id,status){
            layer.confirm('你确定要加入回收站吗？',{
                btn:['确定','取消']
            },function(i){
                layer.close(i);
                layer.load(1);
                $.post('{{url('admin/updateimagestatus')}}',{'_token':'{{csrf_token()}}','id':id,'status':status}, function (res) {
                    layer.closeAll('loading');
                    if(res.status){
                        $("#id"+id).remove();
                        layer.msg(res.msg);
                    }else{
                        layer.msg(res.msg);
                    }
                });
            },function(){

            });
        }
    </script>
    @endsection